package net.Reality.Android.Ant;


import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;

public class StartMenuActivity  extends Activity implements OnClickListener{
	
	private Button newGame;
	private Button loadGame;
	private Button settingsGame;
	private Button helpGame;
	private Thread loadImageThread;
	private ProgressDialog dialog;
	private RelativeLayout layout;
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		 super.onCreate(savedInstanceState);
		 setContentView(R.layout.startmenu);
		 
		 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		 
		 layout = (RelativeLayout) findViewById(R.id.main_menu);
		 layout.setVisibility(View.INVISIBLE);
		 
		 dialog = new ProgressDialog(this);
		 dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		 dialog.setMessage(getString(R.string.sma_progress_dialog_message));
		 
		 newGame = (Button) findViewById(R.id.new_game);
		 loadGame = (Button) findViewById(R.id.load_game);
		 settingsGame = (Button) findViewById(R.id.settings_game);
		 helpGame = (Button) findViewById(R.id.help_game);
		 
		 newGame.setOnClickListener(this);
		 loadGame.setOnClickListener(this);
		 settingsGame.setOnClickListener(this);
		 helpGame.setOnClickListener(this);
		 
		 final Handler mHandler = new Handler();
		 
		 loadImageThread = new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
	
				ImageLoder.getInstance(getApplicationContext());
				
				if(dialog != null)
					dialog.dismiss();
				
				mHandler.post(new Runnable() {
					@Override
					public void run() {
						// TODO Auto-generated method stub
						layout.setVisibility(View.VISIBLE);
					}
				});
			}
		});
		
		loadImageThread.start();
		
		dialog.show();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
		Intent intent = new Intent();
		
		switch(v.getId())
		{
		case R.id.new_game: 	 intent.setClass(getApplicationContext(), AntActivity.class);
								 startActivity(intent);
								 break;
			
		case R.id.load_game:	 intent.setClass(getApplicationContext(), LoadActivity.class);
		 						 startActivity(intent);
		 						 break;
			
		case R.id.settings_game: intent.setClass(getApplicationContext(), SettingsActivity.class);
								 startActivity(intent);
								 break;
			
		case R.id.help_game: 	 intent.setClass(getApplicationContext(), HelpActivity.class);
		 					 	 startActivity(intent);
		 					 	 break;
		}
	}

	@Override
	public void onDestroy()
	{
		super.onDestroy();
		ImageLoder.getInstance(getApplicationContext()).deleteAll();
		System.gc();
	}
	
}
